package designPattern.factory.simpleFactory.improve;

import designPattern.factory.simpleFactory.common.ChessPizza;
import designPattern.factory.simpleFactory.common.GreekPizza;
import designPattern.factory.simpleFactory.common.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class OrderPizza {



    //定义一个简单工厂对象
    SimpleFactory simpleFactory;
    Pizza pizza = null;

    //构造器
    //聚合模式，将simpleFactory作为成员
    public OrderPizza(SimpleFactory simpleFactory){
        setSimpleFactory(simpleFactory);
    }

    public void setSimpleFactory(SimpleFactory simpleFactory){
        String orderType = "";//用户输入

        this.simpleFactory = simpleFactory;//设置见到那工厂对象

        do {
            orderType = getType();
            pizza = this.simpleFactory.creatPizza(orderType);

            //输出Pizza
            if(pizza!=null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("披萨不存在");
                break;
            }
        }while (true);
    }

    //写一个方法，输入获得披萨种类
    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza种类：");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
